<template><divclass="greetings"><h1class="green">{{ msg }}</h1><h3>
You’ve successfully created a project with
<ahref="https://vitejs.dev/"target="_blank"rel="noopener">Vite</a> +
<ahref="https://vuejs.org/"target="_blank"rel="noopener">Vue 3</a>.
</h3></div></template>
VueCli學習筆記 Day-02 - 1Vue專案的組成從組件看組件之間的互動
一、App.vue父組件
App.vue
中可以看到檔案內容結構是由<script setup></script>
、<template></template>
、<style></style>
組成這邊引入了
src/components
中的HelloWorld.vue
HelloWorld
被使用在<div class="wrapper">
中的區塊。二、HelloWorld.vue子組件
<template></template>
中定義了基本的組件 html 結構。<h1 class="green">{{ msg }}</h1>
這邊的{{msg}}
是Vue中的「文本插值」因為Vue中有「自定義標籤」的特性,因此當import組件到某個檔案時,相當於將該組件定義為一個變數,並且可以在該檔案中用該變數做事。
所以 App.vue 的
import HelloWorld from ./components/HelloWorld.vue
讓我們可以在這邊用 HelloWorld 作為自定義標籤,並渲染 HelloWorld.vue 組件的內容。